from django.db import models
from django.contrib.auth import get_user_model

OAUser = get_user_model()
class AbsentStatusChoice(models.IntegerChoices):
    # 审批中
    AUDITING = 1
    # 通过
    PASS = 2
    # 审核拒绝
    REJECT = 3



# Create your models here.
class AbsentType(models.Model):
    name = models.CharField(max_length=100, verbose_name='请假类型')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='请假时间')


class Absent(models.Model):
    # 标题
    title = models.CharField(max_length=200, verbose_name='标题')
    # 请假详细内容
    request_content = models.TextField(verbose_name="请假内容")
    # 请假类型
    absent_type = models.ForeignKey(AbsentType, on_delete=models.CASCADE, verbose_name="请假类型")
    # 发起人
    requester = models.ForeignKey(OAUser, on_delete=models.CASCADE, related_name="absents",
                                  related_query_name="absents", verbose_name="发起人")
    # 审批人
    responder = models.ForeignKey(OAUser, on_delete=models.CASCADE, related_name="sub_absents",
                                  related_query_name="sub_absents", verbose_name="审批人", null=True)
    # 状态
    status = models.IntegerField(choices=AbsentStatusChoice.choices, default=AbsentStatusChoice.AUDITING, verbose_name="状态")
    # 开始日期
    start_date = models.DateField(verbose_name="开始日期")
    # 结束日期
    end_date = models.DateField(verbose_name="结束日期")
    # 发起时间
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="发起时间")
    # 审批回复内容
    response_content = models.TextField(blank=True, verbose_name="审批回复")
    class Meta:
        ordering = ['-create_time']